#include "headfile.h"

int16 speed_left = 0;
int16 speed_right = 0;

void encoder_init(void){
    ctimer_count_init(COUNT_L);//left
	ctimer_count_init(COUNT_R);//right
}

void encoder_exe(void){
    speed_left = (DIR_L == 1)?ctimer_count_read(COUNT_L): -ctimer_count_read(COUNT_L);
	speed_right = (DIR_R == 1)?ctimer_count_read(COUNT_R): -ctimer_count_read(COUNT_R);
	
	speed_left = -speed_left;
	ctimer_count_clean(COUNT_L);
	ctimer_count_clean(COUNT_R);
}

void encoder_print(void){
    uprintf("speed_l:%d,r:%d\r\n",speed_left,speed_right);
}